<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>递四方物流公司首页</title>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="${pageContext.request.contextPath }/css/style.css">
<script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery-2.1.0.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/easyform.js"></script>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/xcConfirm.css"/>
<script src="${pageContext.request.contextPath }/js/xcConfirm.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
	$(document).ready(function(){
		$('#reg-form').easyform();
	});
	
	//点击注册按钮，显示注册信息，隐藏登录信息
	function register(){
		if($("#uid").val() == "" && $("#email").val() == "" && $("#psw1").val() == "" && $("#psw2").val() == ""){
			$("#css-cemail").val("");
			$("#css-cpwd").val("");
			
			$("#log-table").hide();
			$("#re-table").show();
		}else{
			$.ajax({
    			url:'clientRegisterAction.action',//请求的远程url
    			data:$("#reg-form").serialize(),//发送到服务器的数据
    			type:"POST",//默认值: "GET")。请求方式 ("POST" 或 "GET")
    			dataType:"json",//服务器返回的数据类型，有几种返回类型：xml,html,script,json,text(默认)
    			success:function(data){//请求成功后的回调函数
    				 var jsonMap = eval('('+data+')');
    				 var res = jsonMap.res;
    				 var addRes = jsonMap.addRes;
    	   			    if(res == true){
    	   			    	if(addRes == true){
    	   			    		var txt=  "注册成功,您已可以根据邮箱和密码登录Q";
        						window.wxc.xcConfirm(txt, window.wxc.xcConfirm.typeEnum.success);
    	   			    	}else{
    	   			    		var txt=  "注册失败!";
        						window.wxc.xcConfirm(txt, window.wxc.xcConfirm.typeEnum.error);
    	   			    	}
    	   			    }else{
    	   			    	var txt=  "该邮箱已被注册，请更换邮箱!";
    						window.wxc.xcConfirm(txt, window.wxc.xcConfirm.typeEnum.error);
    	   			    }
    			}
    		});
		}
	}
	
	//点击登录按钮，显示登录信息，隐藏注册信息
	function login(){
		if($("#css-cemail").val() == "" && $("#css-cpwd").val() == ""){
			$("#uid").val("");
			$("#email").val("");
			$("#psw1").val("");
			$("#psw2").val("");
			
			$("#log-table").show();
			$("#re-table").hide();
		}else{
			$.ajax({
    			url:'clientLoginAction.action',//请求的远程url
    			data:$("#reg-form").serialize(),//发送到服务器的数据
    			type:"POST",//默认值: "GET")。请求方式 ("POST" 或 "GET")
    			dataType:"json",//服务器返回的数据类型，有几种返回类型：xml,html,script,json,text(默认)
    			success:function(data){//请求成功后的回调函数
    				 var map = eval('('+data+')');
    			     if(map.clientInfo != null){
    			    	 window.parent.location="4px.jsp";
    			     }else{
    			    	var txt = "您输入的账号/密码错误，请重新输入！";
    			    		window.wxc.xcConfirm(txt, window.wxc.xcConfirm.typeEnum.error);
    			     }
    			}
    		});
		}
	}
	
</script>
<style type="text/css">
  body{ background:url(${pageContext.request.contextPath }/img/index.jpg) no-repeat left top;background-size:100%;}
</style>
</head>
<body>
<br>
<div class="form-div">
    <form id="reg-form" action="" method="post">
        <table id="re-table">
            <tr>
                <td>用户名</td>
                <td><input name="reCname" type="text" id="uid" easyform="length:4-16;char-normal;real-time;" message="用户名必须为4—16位的英文字母或数字" easytip="disappear:lost-focus;theme:blue;" ajax-message="用户名已存在!">
                </td>
            </tr>
            <tr>
                <td>email</td>
                <td><input name="reEmail" type="text" id="email" easyform="email;real-time;" message="Email格式要正确" easytip="disappear:lost-focus;theme:blue;" ajax-message="这个Email地址已经被注册过，请换一个吧!"></td>
            </tr>
            <tr>
                <td>密码</td>
                <td><input name="reCpassword1" type="password" id="psw1" easyform="length:6-16;" message="密码必须为6—16位" easytip="disappear:lost-focus;theme:blue;"></td>
            </tr>
            <tr>
                <td>确认密码</td>
                <td><input name="reCpassword2" type="password" id="psw2" easyform="length:6-16;equal:#psw1;" message="两次密码输入要一致" easytip="disappear:lost-focus;theme:blue;"></td>
            </tr>
        </table>
        
        <table id="log-table"  style="display: none">
            <tr>
                <td>email</td>
                <td><input name="cemail" id="css-cemail" type="text"></td>
            </tr>
            <tr>
                <td>密码</td>
                <td><input name="cpassword" id="css-cpwd" type="password"></td>
            </tr>
        </table>

		<div class="buttons">
			<input value="注册" type="button" style="margin-right:20px; margin-top:20px;" onclick="register()">
			<input value="已有账号，我要登录" type="button" style="margin-right:45px; margin-top:20px;" onclick="login()" >
        </div>
		
        <br class="clear">
    </form>
</div>
</body>
</html>